package com.ldj.common;

import java.io.*;
import java.util.*;

public class SystemConfig {

    private static final String DIR = "";
    private String _fileName;
    private ResourceBundle _res;
    public SystemConfig(String fn) {
        _fileName = fn;
        _res = ResourceBundle.getBundle(DIR + "." + fn, Locale.getDefault());
    }
    public String getString(String key) {
        try {
            return en2gbk(_res.getString(key));
        }
        catch (MissingResourceException ex) {
            return "";
        }
        catch (UnsupportedEncodingException ex) {
          throw new RuntimeException(ex);
        }
    }

    public static String getString(String fn, String key) {
        ResourceBundle resources = ResourceBundle.getBundle(DIR + "." + fn,
            Locale.getDefault());
        try {
            return resources.getString(key);
        }
        catch (MissingResourceException ex) {
            return "";
        }
    }

    public static String en2gbk(String src) throws UnsupportedEncodingException {
        String gbString = null;
        gbString = new String(src.getBytes("8859_1"), "GBK");
        return gbString;
    }

    public static Properties readPropFile(String fileName) throws IOException {
        Properties p = new Properties();
        FileInputStream is = new FileInputStream(fileName);
        p.load(is);
        is.close();
        return p;
    }
    public static String getDBLogPath(){
      String path = getString("config","defaultProvider.logpath");
      if (path != null) {
                path = path.trim();
                //Remove trailing slashes.
                while (path.endsWith("/") || path.endsWith("\\")) {
                    path = path.substring(0, path.length()-1);
                  }
            }

      return path;
    }
}
